home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Workspace / Briefcase / Source / PageMargin.m < prev    next >
Text File  |  1992-07-13  |  4KB  |  145 lines

  1. #import "PageMargin.h"
  2. #import <appkit/Application.h>
  3. #import <appkit/Cell.h>
  4. #import <appkit/Matrix.h>
  5. #import <appkit/PrintInfo.h>
  6.  
  7. @implementation PageMargin
  8. /*
  9.  * PageLayout is overridden so that the user can set the margins of
  10.  * the page.  This is a useful feature in most programs.
  11.  *
  12.  * The accessory view is used to add the additional fields, and
  13.  * pickedUnits: is overridden so that the margin is displayed in the
  14.  * currently selected units.  Note that the accessoryView is set
  15.  * in InterfaceBuilder using the outlet mechanism!
  16.  */
  17.  
  18.  
  19. /* Get the values from the fields */
  20. - getValues:(float *)lm right:(float *)rm top:(float *)tm bottom:(float *)bm
  21. {
  22.     float conversion, dummy;
  23.     [self convertOldFactor:&conversion newFactor:&dummy];
  24. /* Values are returned in points, just like PrintInfo */
  25.     *lm = [leftMargin floatValue] / conversion;
  26.     *rm = [rightMargin floatValue] / conversion;
  27.     *tm = [topMargin floatValue] / conversion;
  28.     *bm = [bottomMargin floatValue] / conversion;
  29.     return self;
  30. }
  31.  
  32. /* Set the values as passed */
  33. - setValues:(float)lm right:(float)rm top:(float)tm bottom:(float)bm
  34. {
  35.     float conversion, dummy;
  36.     [self convertOldFactor:&conversion newFactor:&dummy];
  37. /* Values are set in Points, just like PrintInfo */
  38.     [leftMargin setFloatValue:lm*conversion];
  39.     [rightMargin setFloatValue:rm*conversion];
  40.     [topMargin setFloatValue:tm*conversion];
  41.     [bottomMargin setFloatValue:bm*conversion];
  42.     return self;
  43. }
  44.  
  45.  
  46. - pickedUnits:sender
  47. /*
  48.  * Called when the user selects different units (e.g. cm or inches).
  49.  * Must update the margin fields.
  50.  */
  51. {
  52.     float old, new;
  53.  
  54.     [self convertOldFactor:&old newFactor:&new];
  55.     [leftMargin setFloatValue:new * [leftMargin floatValue] / old];
  56.     [rightMargin setFloatValue:new * [rightMargin floatValue] / old];
  57.     [topMargin setFloatValue:new * [topMargin floatValue] / old];
  58.     [bottomMargin setFloatValue:new * [bottomMargin floatValue] / old];
  59.  
  60.     return [super pickedUnits:sender];
  61. }
  62.  
  63. - readPrintInfo
  64. /*
  65.  * Sets the margin fields from the Application-wide PrintInfo.
  66.  */
  67. {
  68.     id pi;
  69.     float conversion, dummy;
  70.     NXCoord left, right, top, bottom;
  71.  
  72.     [super readPrintInfo];
  73.     pi = [NXApp printInfo];
  74.     [self convertOldFactor:&conversion newFactor:&dummy];
  75.     [pi getMarginLeft:&left right:&right top:&top bottom:&bottom];
  76.     [leftMargin setFloatValue:left * conversion];
  77.     [rightMargin setFloatValue:right * conversion];
  78.     [topMargin setFloatValue:top * conversion];
  79.     [bottomMargin setFloatValue:bottom * conversion];
  80.  
  81.     return self;
  82. }
  83.  
  84. - writePrintInfo
  85. /*
  86.  * Sets the margin values in the Application-wide PrintInfo from
  87.  * the margin fields in the panel.
  88.  */
  89. {
  90.     id pi;
  91.     float conversion, dummy;
  92.  
  93.     [super writePrintInfo];
  94.     pi = [NXApp printInfo];
  95.     [self convertOldFactor:&conversion newFactor:&dummy];
  96.     if (conversion) {
  97.     [pi setMarginLeft:[leftMargin floatValue] / conversion
  98.             right:[rightMargin floatValue] / conversion
  99.               top:[topMargin floatValue] / conversion
  100.            bottom:[bottomMargin floatValue] / conversion];
  101.     }
  102.  
  103.     return self;
  104. }
  105.  
  106. /* outlet setting methods */
  107.  
  108. - setPlpAccessory:anObject
  109. {
  110.     plpAccessory = anObject;
  111.     [self setAccessoryView:plpAccessory];
  112.     [self setSideForm:[plpAccessory findViewWithTag:1]];
  113.     [self setTopBotForm:[plpAccessory findViewWithTag:2]];
  114.     return self;
  115. }
  116.  
  117. - setTopBotForm:anObject
  118. {
  119.     [anObject setTarget:ok];
  120.     [anObject setAction:@selector(performClick:)];
  121.     [anObject setNextText:width];
  122.     [anObject setFloatingPointFormat:NO left:2 right:2];
  123.     topMargin = [anObject findCellWithTag:5];
  124.     [topMargin setEntryType:NX_FLOATTYPE];
  125.     bottomMargin = [anObject findCellWithTag:6];
  126.     [bottomMargin setEntryType:NX_FLOATTYPE];
  127.     return self;
  128. }
  129.  
  130. - setSideForm:anObject
  131. {
  132.     [scale setNextText:anObject];
  133.     [anObject setTarget:ok];
  134.     [anObject setAction:@selector(performClick:)];
  135.     [anObject setFloatingPointFormat:NO left:2 right:2];
  136.     leftMargin = [anObject findCellWithTag:3];
  137.     [leftMargin setEntryType:NX_FLOATTYPE];
  138.     rightMargin = [anObject findCellWithTag:4];
  139.     [rightMargin setEntryType:NX_FLOATTYPE];
  140.     return self;
  141. }
  142.  
  143. @end
  144.  
  145.